package com.woniuxy.cloud.userassembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.woniuxy.cloud.entity.TGoodCar;
import com.woniuxy.cloud.entity.TUserCar;
import com.woniuxy.cloud.form.AddUserCarForm;
import com.woniuxy.cloud.userassembly.mapper.TGoodCarMapper;
import com.woniuxy.cloud.userassembly.mapper.TUserCarMapper;
import com.woniuxy.cloud.userassembly.service.ITUserCarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户车型中间表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-09-24
 */
@Service
public class TUserCarServiceImpl extends ServiceImpl<TUserCarMapper, TUserCar> implements ITUserCarService {

    /**
     * 用户新增爱车
     * @param addUserCarForm
     * @return
     */
    @Override
    public Integer insertUserCar(AddUserCarForm addUserCarForm) {
        TUserCar userCar = new TUserCar();
        userCar.setUserCarUserId(addUserCarForm.getUserId()).setUserCarCarSeriesId(addUserCarForm.getUserCarCarSeriesId());
        return getBaseMapper().insert(userCar);
    }

    @Override
    public Integer deleteUserCar(Integer userCarId) {
        return  getBaseMapper().deleteById(userCarId);
    }

    /**
     * 查询用户车型列表
     * @param userId
     * @return
     */
    @Override
    public List<TUserCar> getUserCarListByUserId(Integer userId) {
        QueryWrapper<TUserCar> wrapper = new QueryWrapper<>();
        wrapper.eq("user_car_user_id",userId);
        return getBaseMapper().selectList(wrapper);
    }


    /**
     * 查询用户默认车型
     * @param userId
     * @return Result
     */
    @Override
    public TUserCar getDefaultUserCar(Integer userId) {
        QueryWrapper<TUserCar> wrapper = new QueryWrapper<>();
        wrapper.eq("user_car_user_id",userId).eq("user_car_status","0");
        return  getBaseMapper().selectOne(wrapper);
    }


    /**
     * 修改用户默认车型
     * @param userCarId
     * @param userCarStatus
     * @return Result
     */
    @Override
    public Integer updateUserCarStatus(Integer userCarId, Integer userCarStatus) {
        UpdateWrapper<TUserCar> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("user_car_id",userCarId).set("user_car_status",userCarStatus);
        return getBaseMapper().update(null,updateWrapper);
    }




}
